package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.domain.SystemNews;
import cn.wolfcode.trip.base.mapper.SystemNewsMapper;
import cn.wolfcode.trip.base.query.LikeQueryObject;
import cn.wolfcode.trip.base.service.ISystemNewsService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 骡窝官方
 */
@RestController
@RequestMapping("/systemNews")
public class SystemsNewsController {

    @Autowired
    private ISystemNewsService newsService;
    @Autowired
    private SystemNewsMapper newsMapper;

    @GetMapping("/{userId}")
    public int getSystemNews(@PathVariable Long userId) {
        return newsService.countForSystemNews(userId);
    }

    @GetMapping("/{userId}/systemNews")
    public PageInfo<SystemNews> getCommentMeList(LikeQueryObject qo) {
        qo.setOrderBy("new.createTime desc");
        PageInfo<SystemNews> listForCommentUser = newsService.selectListForSystemNew(qo);
        for(SystemNews news:listForCommentUser.getList()){
            newsMapper.updateCommentState(news.getId());
        }
        return listForCommentUser;
    }
}
